package com.bai;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayOpenPublicTemplateMessageIndustryModifyRequest;
import com.alipay.api.response.AlipayOpenPublicTemplateMessageIndustryModifyResponse;

public class Main {
    // 常量配置
    private static final String URL = "https://openapi.alipay.com/gateway.do";  // 支付宝网关地址
    private static final String APPID = "your-app-id";  // 应用ID
    private static final String PRIVATE_KEY = "your-private-key";  // 应用私钥
    private static final String ALIPAY_PUBLIC_KEY = "your-alipay-public-key";  // 支付宝公钥
    private static final String FORMAT = "json";  // 请求格式，固定值 json
    private static final String CHARSET = "UTF-8";  // 字符集
    private static final String SIGN_TYPE = "RSA2";  // 签名类型

    public static void main(String[] args) throws AlipayApiException {
        // 配置支付宝SDK
        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setServerUrl(URL);  // 设置网关地址
        alipayConfig.setAppId(APPID);  // 设置应用ID
        alipayConfig.setPrivateKey(PRIVATE_KEY);  // 设置应用私钥
        alipayConfig.setFormat(FORMAT);  // 设置请求格式
        alipayConfig.setCharset(CHARSET);  // 设置字符集
        alipayConfig.setSignType(SIGN_TYPE);  // 设置签名类型
        alipayConfig.setAlipayPublicKey(ALIPAY_PUBLIC_KEY);  // 设置支付宝公钥

        // 实例化AlipayClient，初始化支付SDK
        AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig);

        //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.open.public.template.message.industry.modify
        AlipayOpenPublicTemplateMessageIndustryModifyRequest request = new AlipayOpenPublicTemplateMessageIndustryModifyRequest();
        //SDK已经封装掉了公共参数，这里只需要传入业务参数
        //此次只是参数展示，未进行字符串转义，实际情况下请转义
        request.setBizContent("  {" +
                "    \"primary_industry_name\":\"IT科技/IT软件与服务\"," +
                "    \"primary_industry_code\":\"10001/20102\"," +
                "    \"secondary_industry_code\":\"10001/20102\"," +
                "    \"secondary_industry_name\":\"IT科技/IT软件与服务\"" +
                " }");
        AlipayOpenPublicTemplateMessageIndustryModifyResponse response = alipayClient.execute(request);
        //调用成功，则处理业务逻辑
        if (response.isSuccess()) {
            //.....
        }
    }
}